import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddressDemo {
    public static void main(String[] args) throws UnknownHostException {
        InetAddress address = InetAddress.getByName("192.168.191.1");
        String name = address.getHostName();   //获取主机名 DESKTOP-5HG488B
        String ip = address.getHostAddress();  //获取主机地址 192.168.191.1
        InetAddress localHost = InetAddress.getLocalHost();
        System.out.println("name : " + name);
        System.out.println("IP : " + ip);
        System.out.println("LocalHost : " + localHost );  //得到 主机名/IP

//        name : DESKTOP-5HG488B
//        IP : 192.168.191.1
    }
}
